# == Schema Info
# Schema version: 20091029102158
#
# Table name: assets
#
#  id                :integer(4)      not null, primary key
#  assetable_id      :integer(4)      not null
#  user_id           :integer(4)
#  assetable_type    :string(25)      not null
#  data_content_type :string(255)
#  data_file_name    :string(255)
#  data_file_size    :integer(4)
#  locale            :integer(1)      default(0)
#  type              :string(25)
#  created_at        :datetime
#  updated_at        :datetime

class Asset < ActiveRecord::Base
  belongs_to :user
  belongs_to :assetable, :polymorphic => true
  
  def url(*args)
    data.url(*args)
  end
  
  def filename
    data_file_name
  end
  
  def content_type
    data_content_type
  end
  
  def size
    data_file_size
  end
  
  def to_xml(options = {})
    xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])

    xml.tag!(self.type.to_s.downcase) do
      xml.filename{ xml.cdata!(self.filename) }
      xml.size self.size
      xml.path{ xml.cdata!(self.url) }
      
      xml.styles do
        self.styles.each do |style|
          xml.tag!(t.style, self.url(style))
        end
      end unless self.styles.empty?
    end
  end
end